package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// Material 素材库
type Material struct {
	ID             string `json:"id" gorm:"column:id;primaryKey;type:int;size:64;comment:主键id"`
	MerchantID     string `json:"merchant_id" gorm:"column:merchant_id;type:int;size:64;index:merchant_id;default:0;comment:所属商户"`
	MaterialID     int64  `json:"material_id" gorm:"column:material_id;type:int;size:64;default:0;comment:素材ID"`
	Name           string `json:"name" gorm:"column:name;index:name;type:string;size:40;comment:名称"`
	Type           int    `json:"type" gorm:"column:type;type:int;size:8;default:1;comment:类型:1文案语音 2音频语音 3情绪表情 4灯光素材"`
	FolderID       string `json:"folder_id" gorm:"column:folder_id;type:string;size:30;not null;default:'0';comment:分组id"`
	Content        string `json:"content" gorm:"column:content;type:string;size:255;default:'';comment:内容"`
	Status         int    `json:"status" gorm:"column:status;type:int;size:8;default:1;comment:状态:1启用 2禁用"`
	FilePath       string `json:"file_path" gorm:"column:file_path;type:string;size:255;default:'';comment:文件地址"`
	AuditStatus    int    `json:"audit_status" gorm:"column:audit_status;type:int;size:8;default:0;comment:审核状态:0未审核 1审核通过 2审核拒绝"`
	CreateUser     string `json:"create_user" gorm:"column:create_user;type:string;size:40;default:'';comment:创建用户"`
	CreateUsername string `json:"create_username" gorm:"column:create_username;type:string;size:50;default:'';comment:创建用户名"`
	CreatedAt      int64  `json:"-" gorm:"column:created_at;autoCreateTime;type:int;size:64;comment:创建时间"`
	UpdatedAt      int64  `json:"-" gorm:"column:updated_at;autoUpdateTime;type:int;size:64;comment:更新时间"`
}

// TableName 表名
func (Material) TableName() string {
	return "material_v2"
}

// BeforeCreate 自增id
func (l *Material) BeforeCreate(tx *gorm.DB) (err error) {
	if l.ID != "" {
		return nil
	}
	// id为空时，自动添加id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	l.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &Material{})
}
